/*
* 设备巡检详情
* */

import 'package:center_beijing/api/task_api.dart';
import 'package:center_beijing/common/styles.dart';
import 'package:center_beijing/config/global_config.dart';
import 'package:center_beijing/config/routeConfig.dart';
import 'package:center_beijing/widgets/custom_loading_widget.dart';
import 'package:center_beijing/widgets/imageSelect_widget.dart';
import 'package:center_beijing/widgets/imagesWatch_widget2.dart';
import 'package:center_beijing/widgets/photo_view_gallery.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class EquipmentInspectionDetail extends StatefulWidget {
  @override
  _EquipmentInspectionDetailState createState() =>
      _EquipmentInspectionDetailState();
}

class _EquipmentInspectionDetailState extends State<EquipmentInspectionDetail>
    with SingleTickerProviderStateMixin {
  AnimationController _controller;
  CustomLoading loading = CustomLoading.withMessage('读取中...');
  bool hide = false;
  bool hide2 = true;
  var equipment = Get.arguments['equipment'];
  var planId = Get.arguments['planId'];
  var detail = Map();
  List dataSource = [1, 2];

  @override
  void initState() {
    _controller = AnimationController(vsync: this);
    super.initState();
    this.getEquipmentCheckDetail();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  getEquipmentCheckDetail() async {
    var pass = {
      'equipmentId': equipment['id'],
      'planId': planId,
    };
    loading.show(delay: 30);
    var result = await getEquipmentCheckHistory(pass);
    loading.dismiss();
    if (result != null) {
      this.setState(() {
        detail = result;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('巡检详情'),
        actions: [
          GestureDetector(
            onTap: () {
              Get.toNamed(RouteConfig.addEquipmentInspection,
                  arguments: {'equipment': equipment, 'planId': planId});
            },
            child: Container(
              alignment: Alignment.center,
              padding: EdgeInsets.fromLTRB(Styles.spacing8, Styles.spacing4,
                  Styles.spacing8, Styles.spacing4),
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.all(Radius.circular(4.0.r))),
              child: Text(
                '开始检查',
                style: TextStyle(
                    color: Styles.ShareWhite, fontSize: Styles.NormalFont),
              ),
            ),
          )
        ],
      ),
      body: Container(
        color: Styles.MainBackgroundColor,
        padding:
            EdgeInsets.fromLTRB(0, 0, 0, MediaQuery.of(context).padding.bottom),
        child: SingleChildScrollView(
          child: Column(
            children: [
              Container(
                padding: EdgeInsets.fromLTRB(Styles.spacing8, Styles.spacing8,
                    Styles.spacing8, Styles.spacing8),
                child: Row(
                  children: [
                    Container(
                      height: 26.h,
                      width: 4,
                      color: Styles.BlueColor,
                      margin: EdgeInsets.only(right: Styles.spacing8),
                    ),
                    Text(
                      '基本信息',
                      style: TextStyle(
                          color: Styles.DetailColor,
                          fontSize: Styles.Middle16Font),
                    ),
                  ],
                ),
              ),
              Container(
                color: Colors.white,
                padding: EdgeInsets.fromLTRB(Styles.spacing16, Styles.spacing8,
                    Styles.spacing16, Styles.spacing8),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    equipment['equipmentPhoto'] != null
                        ? GestureDetector(
                      onTap: (){
                        Navigator.of(context).push(new FadeRoute(
                            page: PhotoViewGalleryScreen(
                                images: ["${GlobalConfig.baseUrl}fs/irest/file/mps_fileTransferHandler/image?id=${equipment['equipmentPhoto']}&ZJQFSESSION=${GlobalConfig.session}"], //传入图片list
                                index: 0, //传入当前点击的图片的index
                                heroTag: '')));
                      },
                      child: Container(
                        child: Image.network(
                          "${GlobalConfig.baseUrl}fs/irest/file/mps_fileTransferHandler/image?id=${equipment['equipmentPhoto']}&ZJQFSESSION=${GlobalConfig.session}",
                          height: 80.h,
                          width: 80.w,
                          fit: BoxFit.fill,
                        ),
                      ),
                    )
                        : Container(
                            child: Image.asset(
                            'assets/images/default_image.png',
                            height: 80.h,
                            width: 80.w,
                            fit: BoxFit.fill,
                          )),
                    Expanded(
                        child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          alignment: Alignment.centerLeft,
                          margin: EdgeInsets.fromLTRB(
                              Styles.spacing8, 0, Styles.spacing8, 0),
                          child: Text(
                            equipment['equipmentName'] != null
                                ? equipment['equipmentName']
                                : '--',
                            style: TextStyle(
                                color: Styles.DetailColor,
                                fontSize: Styles.Middle16Font),
                          ),
                        ),
                        Container(
                          alignment: Alignment.centerLeft,
                          margin: EdgeInsets.fromLTRB(Styles.spacing8,
                              Styles.spacing8, Styles.spacing8, 0),
                          child: Text(
                            equipment['address'] != null
                                ? equipment['address']
                                : '--',
                            style: TextStyle(
                                color: Styles.DetailColor,
                                fontSize: Styles.NormalFont),
                          ),
                        ),
                      ],
                    ))
                  ],
                ),
              ),

              Container(
                padding: EdgeInsets.fromLTRB(Styles.spacing16, Styles.spacing8,
                    Styles.spacing16, Styles.spacing8),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      '关联检查内容',
                      style: TextStyle(
                          color: Styles.DetailColor,
                          fontSize: Styles.NormalFont),
                    ),
                    Row(
                      children: [
                        Text(
                          detail['checkRecordList'] != null
                              ? detail['checkRecordList'].length.toString()
                              : '0',
                          style: TextStyle(
                              color: Styles.DetailColor,
                              fontSize: Styles.NormalFont),
                        ),
                        GestureDetector(
                          onTap: () {
                            this.setState(() {
                              hide = !hide;
                            });
                          },
                          child: Container(
                            margin: EdgeInsets.only(left: Styles.spacing8),
                            decoration: BoxDecoration(
                              color: Styles.GrayLight,
                            ),
                            padding: EdgeInsets.fromLTRB(
                                Styles.spacing4, 0, Styles.spacing4, 0),
                            child: Text(
                              !hide ? '点击收起' : '点击查看',
                              style: TextStyle(
                                  color: Styles.BlueColor,
                                  fontSize: Styles.SmallFont),
                            ),
                          ),
                        )
                      ],
                    )
                  ],
                ),
              ),
              hide
                  ? Container()
                  : detail['checkRecordList'] != null
                      ? Container(
                          color: Colors.white,
                          padding: EdgeInsets.fromLTRB(
                              Styles.spacing16,
                              Styles.spacing8,
                              Styles.spacing16,
                              Styles.spacing8),
                          alignment: Alignment.centerLeft,
                          child: Column(
                            children:
                                detail['checkRecordList'].map<Widget>((item) {
                              return Container(
                                alignment: Alignment.centerLeft,
                                padding: EdgeInsets.fromLTRB(
                                    0, Styles.spacing4, 0, Styles.spacing4),
                                child: Text(
                                  '${item['checkName']}：${item['checkResultName']}',
                                  style: TextStyle(
                                      color: Styles.DetailColor,
                                      fontSize: Styles.NormalFont),
                                ),
                              );
                            }).toList(),
                          ),
                        )
                      : Container(),
              Container(
                padding: EdgeInsets.fromLTRB(Styles.spacing8, Styles.spacing8,
                    Styles.spacing8, Styles.spacing8),
                child: Row(
                  children: [
                    Container(
                      height: 26.h,
                      width: 4,
                      color: Styles.BlueColor,
                      margin: EdgeInsets.only(right: Styles.spacing8),
                    ),
                    Text(
                      '检查信息',
                      style: TextStyle(
                          color: Styles.DetailColor,
                          fontSize: Styles.Middle16Font),
                    ),
                  ],
                ),
              ),
              Container(
                padding: EdgeInsets.fromLTRB(Styles.spacing16, Styles.spacing8,
                    Styles.spacing16, Styles.spacing8),
                color: Colors.white,
                alignment: Alignment.centerLeft,
                child: Text(
                  (detail['equRecord'] != null&&detail['equRecord']['checkResult'] != null)
                      ? detail['equRecord']['checkResult']
                      : '--',
                  style: TextStyle(
                      color: Styles.DetailColor, fontSize: Styles.NormalFont),
                ),
              ),
              (detail['equRecordAttList'] != null &&
                      detail['equRecordAttList'].length > 0)
                  ? Column(
                      children: [
                        Container(
                          padding: EdgeInsets.fromLTRB(
                              Styles.spacing8,
                              Styles.spacing8,
                              Styles.spacing8,
                              Styles.spacing8),
                          child: Row(
                            children: [
                              Container(
                                height: 26.h,
                                width: 4,
                                color: Styles.BlueColor,
                                margin: EdgeInsets.only(right: Styles.spacing8),
                              ),
                              Text(
                                '现场图片',
                                style: TextStyle(
                                    color: Styles.DetailColor,
                                    fontSize: Styles.Middle16Font),
                              ),
                            ],
                          ),
                        ),
                        Container(
                          color: Colors.white,
                          child: ImagesWatchWidget2(
                            photos:
                                detail['equRecordAttList'].map<String>((image) {
                              return "${GlobalConfig.baseUrl}fs/irest/file/mps_fileTransferHandler/image?id=${image['fileId']}&ZJQFSESSION=${GlobalConfig.session}";
                            }).toList(),
                          ),
                        )
                      ],
                    )
                  : Container()
              // Expanded(
              //     child: SingleChildScrollView(
              //   child: Container(
              //     color: Colors.white,
              //     padding: EdgeInsets.fromLTRB(Styles.spacing8, Styles.spacing8,
              //         Styles.spacing8, Styles.spacing8),
              //     margin:
              //         EdgeInsets.fromLTRB(0, Styles.spacing4, 0, Styles.spacing4),
              //     child: Column(
              //       children: this.dataSource.asMap().keys.map<Widget>((index) {
              //         return Container(
              //           margin: EdgeInsets.fromLTRB(
              //               0, Styles.spacing4, 0, Styles.spacing4),
              //           child: Row(
              //             crossAxisAlignment: CrossAxisAlignment.start,
              //             children: [
              //               Container(
              //                 padding: EdgeInsets.all(Styles.spacing8),
              //                 decoration: BoxDecoration(
              //                   color: Styles.BlueColor,
              //                   shape: BoxShape.circle,
              //                 ),
              //                 child: Text(
              //                   (this.dataSource.length - index).toString(),
              //                   style: TextStyle(
              //                       color: Styles.ShareWhite,
              //                       fontSize: Styles.NormalFont),
              //                 ),
              //               ),
              //               Expanded(
              //                   child: Container(
              //                 padding: EdgeInsets.all(Styles.spacing8),
              //                 margin: EdgeInsets.fromLTRB(
              //                     Styles.spacing8, 0, Styles.spacing8, 0),
              //                 decoration: BoxDecoration(
              //                     color: Styles.GrayLight,
              //                     borderRadius:
              //                         BorderRadius.all(Radius.circular(4.0.r)),
              //                     border: Border.all(
              //                         width: 1, color: Styles.LineColor)),
              //                 child: Column(
              //                   crossAxisAlignment: CrossAxisAlignment.start,
              //                   children: [
              //                     Container(
              //                       padding: EdgeInsets.fromLTRB(
              //                           0, Styles.spacing4, 0, Styles.spacing4),
              //                       child: Row(
              //                         mainAxisAlignment:
              //                             MainAxisAlignment.spaceBetween,
              //                         children: [
              //                           Text(
              //                             '检查时间：2021-11-05 10:56:14',
              //                             style: TextStyle(
              //                                 color: Styles.DetailColor,
              //                                 fontSize: Styles.NormalFont),
              //                           ),
              //                           GestureDetector(
              //                             onTap: () {
              //                               this.setState(() {
              //                                 hide2 = !hide2;
              //                               });
              //                             },
              //                             child: Container(
              //                               padding: EdgeInsets.only(
              //                                   right: Styles.spacing8),
              //                               child: Text(
              //                                 hide2 ? '查看' : '收起',
              //                                 style: TextStyle(
              //                                     color: Styles.BlueColor,
              //                                     fontSize: Styles.NormalFont),
              //                               ),
              //                             ),
              //                           )
              //                         ],
              //                       ),
              //                     ),
              //                     Container(
              //                       padding: EdgeInsets.fromLTRB(
              //                           0, Styles.spacing4, 0, Styles.spacing4),
              //                       child: Row(
              //                         mainAxisAlignment:
              //                             MainAxisAlignment.spaceBetween,
              //                         children: [
              //                           Text(
              //                             '检查人：张家丰',
              //                             style: TextStyle(
              //                                 color: Styles.DetailColor,
              //                                 fontSize: Styles.NormalFont),
              //                           ),
              //                           Container(
              //                             padding: EdgeInsets.only(
              //                                 right: Styles.spacing8),
              //                             child: Text(
              //                               '隐患1个',
              //                               style: TextStyle(
              //                                   color: Styles.RedColor,
              //                                   fontSize: Styles.NormalFont),
              //                             ),
              //                           )
              //                         ],
              //                       ),
              //                     ),
              //                     !hide2
              //                         ? Column(
              //                             crossAxisAlignment:
              //                                 CrossAxisAlignment.start,
              //                             children: [
              //                               Container(
              //                                 padding: EdgeInsets.fromLTRB(
              //                                     0,
              //                                     Styles.spacing8,
              //                                     0,
              //                                     Styles.spacing8),
              //                                 child: Text(
              //                                   '巡检信息',
              //                                   style: TextStyle(
              //                                       color: Styles.DetailColor,
              //                                       fontSize: Styles.NormalFont),
              //                                 ),
              //                               ),
              //                               Container(
              //                                 padding: EdgeInsets.fromLTRB(
              //                                     0, 0, 0, Styles.spacing8),
              //                                 child: Text(
              //                                   '该设备外观部分良好，设备运转正常',
              //                                   style: TextStyle(
              //                                       color: Styles.LeftTitleColor,
              //                                       fontSize: Styles.NormalFont),
              //                                 ),
              //                               ),
              //                               Container(
              //                                 padding: EdgeInsets.fromLTRB(
              //                                     0,
              //                                     Styles.spacing8,
              //                                     0,
              //                                     Styles.spacing8),
              //                                 child: Text(
              //                                   '现场照片',
              //                                   style: TextStyle(
              //                                       color: Styles.DetailColor,
              //                                       fontSize: Styles.NormalFont),
              //                                 ),
              //                               ),
              //                               ImagesWatchWidget2(
              //                                 photos: this.photos,
              //                               ),
              //                               Container(
              //                                 padding: EdgeInsets.fromLTRB(
              //                                     0,
              //                                     Styles.spacing8,
              //                                     0,
              //                                     Styles.spacing8),
              //                                 child: Text(
              //                                   '隐患',
              //                                   style: TextStyle(
              //                                       color: Styles.DetailColor,
              //                                       fontSize: Styles.NormalFont),
              //                                 ),
              //                               ),
              //                               Container(
              //                                 padding: EdgeInsets.fromLTRB(
              //                                     Styles.spacing16,
              //                                     Styles.spacing8,
              //                                     Styles.spacing16,
              //                                     Styles.spacing8),
              //                                 child: Row(
              //                                   mainAxisAlignment:
              //                                       MainAxisAlignment
              //                                           .spaceBetween,
              //                                   children: [
              //                                     Text(
              //                                       '设备外观是否损坏',
              //                                       style: TextStyle(
              //                                           color: Styles.DetailColor,
              //                                           fontSize:
              //                                               Styles.NormalFont),
              //                                     ),
              //                                     Text(
              //                                       '是',
              //                                       style: TextStyle(
              //                                           color: Styles.RedColor,
              //                                           fontSize:
              //                                               Styles.NormalFont),
              //                                     ),
              //                                   ],
              //                                 ),
              //                               ),
              //                             ],
              //                           )
              //                         : Container(),
              //                   ],
              //                 ),
              //               ))
              //             ],
              //           ),
              //         );
              //       }).toList(),
              //     ),
              //   ),
              // ))
            ],
          ),
        ),
      ),
    );
  }
}
